home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14642
/
14642.xpi
/
chrome
/
content
/
historyThumbnail.js
< prev
next >
Wrap
Text File
|
2009-10-07
|
13KB
|
345 lines
/* Copyright 2009, Boomtango.com. All Rights Reserved. */
/* historyThumbnail.js
* Responsible for category view
*/
bthistory.controllers["thumbnail"] = {
onHistoryAdd: function(dataset) {
bthistory.updateView();
},
onHistoryChange: function(data) {
bthistory.app.debug("thumbnail::onHistoryChange");
},
handleUpArrow: function(){
var sels = document.getElementsByClassName("selected");
var body = document.getElementById("body");
var items = document.getElementsByClassName("historyItem");
if(items.length == 0){
return;
}
if(sels.length == 0){
var node = items[items.length - 1];
bthistory.selectNode(node);
} else {
var sel = sels[0];
if(sel.previousSibling){
bthistory.selectNode(sel.previousSibling);
} else {
if(sel.parentNode.previousSibling){
bthistory.selectNode(sel.parentNode.previousSibling.lastChild);
} else {
var nextarrow = document.getElementById("searchprev");
if(nextarrow){
nextarrow.click();
}
}
}
}
},
handleDownArrow: function(){
var sels = document.getElementsByClassName("selected");
var body = document.getElementById("body");
var items = document.getElementsByClassName("historyItem");
if(items.length == 0){
return;
}
if(sels.length == 0){
var node = items[0];
bthistory.selectNode(node);
} else {
var sel = sels[0];
if(sel.nextSibling){
bthistory.selectNode(sel.nextSibling);
} else {
if(sel.parentNode.nextSibling){
bthistory.selectNode(sel.parentNode.nextSibling.firstChild);
} else {
var nextarrow = document.getElementById("searchnext");
if(nextarrow){
nextarrow.click();
}
}
}
}
},
handleResize: function(){
bthistory.updateView();
},
queryTracker: function(types, filter){
this.calcMetrics();
return bthistory.storage.queryTrackerByThumbnail(
bthistory._range.start,
bthistory._range.end,
types,
filter,
bthistory.currOffset,
this.numcells
);
},
calcMetrics: function(){
var body = document.getElementById("body");
this.width = body.boxObject.width;
this.height = body.boxObject.height - 20;
this.colwidth = 240 + 8 + 8;
this.colheight = 180 + 32 + 8 + 8;
this.numcols = Math.max(Math.floor(this.width/this.colwidth), 1);
this.numrows = Math.max(Math.floor(this.height/this.colheight), 1);
this.numcells = this.numcols * this.numrows;
},
createItem: function(data){
var box = document.createElement('vbox');
box.setAttribute('style', 'width: ' + this.colwidth + 'px;');
box.id = 'thumbnail.' + data.fstrowid;
box.className = "historyItem";
box.setAttribute('contentID', data.ftsrowid);
var hbox, label, spacer;
var app = bthistory.app;
var thumbid = app.getThumbID(data.url);
var thumb = app.getThumb(thumbid.id);
if(thumb.length){
var img = document.createElement('image');
img.setAttribute('src',thumb);
img.className = 'thumb';
box.appendChild(img);
} else {
var vbox = document.createElement('vbox');
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
spacer.setAttribute('height', '80');
vbox.appendChild(spacer);
vbox.className = "nothumb";
label = document.createElement('label');
label.setAttribute('value', app.getString('history.nopreview'));
label.className = 'nopreview';
vbox.appendChild(label);
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
spacer.setAttribute('height', '80');
vbox.appendChild(spacer);
/*
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
spacer.setAttribute('height', '180');
hbox.appendChild(spacer);
label = document.createElement('label');
label.setAttribute('value', app.getString('history.nopreview'));
label.className = 'nopreview';
hbox.appendChild(label);
hbox.appendChild(spacer);
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
spacer.setAttribute('height', '180');
hbox.appendChild(spacer);
*/
box.appendChild(vbox);
}
// title
hbox = document.createElement('hbox');
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
hbox.appendChild(spacer);
label = document.createElement('label');
label.setAttribute('flex', '1');
label.setAttribute('crop', 'end');
label.setAttribute('value', data.title || data.url);
hbox.appendChild(label);
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
hbox.appendChild(spacer);
box.appendChild(hbox);
// date
hbox = document.createElement('hbox');
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
hbox.appendChild(spacer);
label = document.createElement('label');
label.setAttribute('flex', '1');
label.setAttribute('crop', 'end');
label.setAttribute('value', bthistory.datestring(data.starttime));
label.setAttribute('style', 'color: #666;');
hbox.appendChild(label);
spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
hbox.appendChild(spacer);
box.appendChild(hbox);
return box;
},
loadView: function(selectID){
var data = bthistory._data.data;
var total = bthistory._data.total;
var len = data.length;
this.total = total;
if(!len){
var body = document.getElementById("body");
var label= document.createElement("label");
label.id = "nodatafound";
label.setAttribute("value", bthistory.app.getString("history.nodatafound"));
label.className = "nodatafound";
body.appendChild(label);
} else {
var body = document.getElementById("body");
var container = document.createElement('vbox');
container.id = "thumb.container";
var grid = document.createElement('grid');
var columns = document.createElement('columns');
var rows = document.createElement('rows');
var numcols = this.numcols;
for(var x=0; x<numcols; x++){
var col = document.createElement('column');
columns.appendChild(col);
}
len = Math.min(len, this.numcells);
var currCol = 0;
var row = null;
for(var x = 0; x < len; x++){
var item = data[x];
if(!currCol){
if(row){
rows.appendChild(row);
}
row = document.createElement('row');
}
row.appendChild(this.createItem(item));
currCol = (currCol + 1) % numcols;
}
rows.appendChild(row);
this.currCol = currCol;
grid.appendChild(columns);
grid.appendChild(rows);
container.appendChild(grid);
body.appendChild(container);
if(selectID){
var node = document.getElementById("thumbnail." + selectID);
if(node){
bthistory.selectNode(node);
}
}
this.loadPagination();
var header = document.getElementById("body_header");
var hbox = document.createElement('hbox');
var label = document.createElement("label");
label.setAttribute("value",
bthistory.app.getString(
"results.count",
(bthistory.currOffset + 1).toString(),
(bthistory.currOffset + data.length).toString(),
total.toString()
)
);
hbox.appendChild(label);
var spacer = document.createElement('spacer');
spacer.setAttribute('flex', '100');
hbox.appendChild(spacer);
header.appendChild(hbox);
header.setAttribute("hidden", "false");
}
},
loadPagination: function(){
var container = document.getElementById('thumb.container');
var hbox = document.createElement("hbox");
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
hbox.appendChild(spacer);
const ITEMSPERPAGE = this.numcells;
if(bthistory.currOffset){
var vbox = document.createElement("vbox");
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
vbox.appendChild(spacer);
var label= document.createElement("image");
label.id = "searchprev";
label.className = "resultsarrow";
label.setAttribute('src', 'chrome://boomtango/skin/arrow_left.png');
var start = bthistory.currOffset - ITEMSPERPAGE;
if(start < 0) {
start = 0;
}
this.loadPageClick(label, start);
vbox.appendChild(label);
hbox.appendChild(vbox);
}
var startIndex = Math.floor(bthistory.currOffset / (ITEMSPERPAGE * 10)) * 10;
var currIndex = Math.floor(bthistory.currOffset / ITEMSPERPAGE);
var endIndex = startIndex + 10;
if(this.total < endIndex * ITEMSPERPAGE){
endIndex = Math.floor(this.total / ITEMSPERPAGE) + ((this.total % ITEMSPERPAGE) > 0 ? 1 : 0);
}
for(var x = startIndex; x < endIndex; x++){
if(x != currIndex){
var label= document.createElement("label");
var start = x * ITEMSPERPAGE;
this.loadPageClick(label, start);
label.className = "resultspagelink";
label.setAttribute("value", (x + 1).toString());
hbox.appendChild(label);
} else {
var label= document.createElement("label");
var start = x * ITEMSPERPAGE;
label.className = "resultscurrpage";
label.setAttribute("value", (x + 1).toString());
hbox.appendChild(label);
}
}
if(bthistory.currOffset + ITEMSPERPAGE < this.total){
var vbox = document.createElement("vbox");
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
vbox.appendChild(spacer);
var label= document.createElement("image");
label.className = "resultsarrow";
label.setAttribute('src', 'chrome://boomtango/skin/arrow_right.png');
label.id = "searchnext";
var start = bthistory.currOffset + ITEMSPERPAGE;
this.loadPageClick(label, start);
vbox.appendChild(label);
hbox.appendChild(vbox);
}
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
hbox.appendChild(spacer);
container.appendChild(hbox);
},
gotoPage: function(start){
bthistory.currOffset = start;
bthistory.resetHash();
bthistory.updateView();
},
loadPageClick: function(label, start){
var self = this;
label.addEventListener(
"click",
function(){
self.gotoPage(start);
},
false
);
}
};